/** @file    wBuilding_BuildingGeometry.cpp
 *  @author  Alessandro Polo
 *  @version $Id: wBuilding_BuildingGeometry.cpp 2891 2010-08-12 01:58:59Z alex $
 *  @brief
 * File containing methods for the wosh::gui::wBuilding_BuildingGeometry class.
 * The header for this class can be found in wBuilding_BuildingGeometry.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

 #include "wBuilding_BuildingGeometry.h"

 #include <core/ObjectAllocator.h>
 #include <framework/gui/GuiUtilities.h>

 #include "ui_wBuilding_BuildingGeometry.h"
 #include "ui_wBuilding_BuildingGeometry_Point3D.h"


using namespace std;
namespace wosh {
 namespace gui {

wBuilding_BuildingGeometry_Point3D::wBuilding_BuildingGeometry_Point3D( QWidget* parent )
	: QWidget(parent) {
	this->m_ui = new Ui::wBuilding_BuildingGeometry_Point3D();
	this->m_ui->setupUi(this);

	loadObject(NULL);
 }

wBuilding_BuildingGeometry_Point3D::~wBuilding_BuildingGeometry_Point3D() {
	delete this->m_ui;
 }

WRESULT wBuilding_BuildingGeometry_Point3D::loadObject( const wosh::building::Point3D* point ) {
	if ( point == NULL ) {
		this->m_ui->dspinX->setValue(0.0);
		this->m_ui->dspinY->setValue(0.0);
		this->m_ui->dspinZ->setValue(0.0);
	 }
	else {
		this->m_ui->dspinX->setValue(point->x);
		this->m_ui->dspinY->setValue(point->y);
		this->m_ui->dspinZ->setValue(point->z);
	 }
	return WRET_OK;
 }

WRESULT wBuilding_BuildingGeometry_Point3D::saveObject( wosh::building::Point3D* point ) const {
	if ( point == point ) return WRET_ERR_PARAM;
	point->x = this->m_ui->dspinX->value();
	point->y = this->m_ui->dspinY->value();
	point->z = this->m_ui->dspinZ->value();
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::gui::wBuilding_BuildingGeometry, "wosh::gui::IWidgetSerializable", 1.0, _static_wBuilding_BuildingGeometry )
 WOSH_GUI_MAP(wosh::gui::wBuilding_BuildingGeometry, "wosh::building::BuildingGeometry", 0.0, _static_Map_wBuilding_BuildingGeometry )

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

wBuilding_BuildingGeometry::wBuilding_BuildingGeometry( QWidget* parent )
	: QWidget(parent) {
	this->m_ui = new Ui::wBuilding_BuildingGeometry();
	this->m_ui->setupUi(this);

	setWindowIcon( GuiUtilities::createIconFor( getSerializableType() ) );
	setWindowTitle( getSerializableType() );

	loadObject(NULL);
 }

wBuilding_BuildingGeometry::~wBuilding_BuildingGeometry() {
	delete this->m_ui;
 }

void wBuilding_BuildingGeometry::changeEvent(QEvent *e) {
	QWidget::changeEvent(e);
	if ( e->type() == QEvent::LanguageChange )
		this->m_ui->retranslateUi(this);
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

WRESULT wBuilding_BuildingGeometry::loadObject( const wosh::building::BuildingGeometry* bgeom ) {
	if ( bgeom == NULL ) {
		this->m_ui->wPointPosition->loadObject(NULL);
		this->m_ui->wPointBoundingBox->loadObject(NULL);
	 }
	else {
		this->m_ui->wPointPosition->loadObject(&bgeom->getPosition());
		this->m_ui->wPointBoundingBox->loadObject(&bgeom->getBoundingBox());
	 }
	return WRET_OK;
 }

WRESULT wBuilding_BuildingGeometry::saveObject( wosh::building::BuildingGeometry* bgeom ) const {
	if ( bgeom == NULL ) return WRET_ERR_PARAM;
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////


 }; // namespace gui
}; // namespace wosh
